//
//  ResetPdVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/11.
//  Copyright © 2016年 阳光. All rights reserved.
//  修改密码的设置重置密码界面

#import "ResetPdVC.h"
#import "LoginVC.h"

@interface ResetPdVC ()

@property(nonatomic,strong)LeftTitle_TextFieldView *resetPdView;

@property(nonatomic,strong)LeftTitle_TextFieldView *againPdView;

@end

@implementation ResetPdVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor=WhiteColor;
    
    self.title = NSLocalizedString(@"Change Password", nil);//修改密码;//@"重置密码";
    
    [self initNavBarBtnItem];
    
    [self initMainView];
    
}

-(void)initMainView
{
    UIView *topLine=[UIView new];
    [self.view addSubview:topLine];
    topLine.backgroundColor=MAIN_BACK_COLOR;
    [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(APPW,1));
        make.top.mas_equalTo(0);
    }];
    
    // 新密码
    {
        _resetPdView=[[LeftTitle_TextFieldView alloc]initWithTitle:NSLocalizedString(@"NewPassWord", nil) placeholder:NSLocalizedString(@"EnterNewPassword", nil)];//@"新密码" :@"请输入新密码"];

        ViewBorderRadius(_resetPdView,kmargin/2,.5,ColorBDBDBD);
        [self.view addSubview:_resetPdView];
        _resetPdView.textField.secureTextEntry=YES;
        [_resetPdView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(kmargin*2+1);
            make.left.mas_equalTo(kmargin*3);
            make.size.mas_equalTo(CGSizeMake(APPW-kmargin*6,40));
        }];
    }
    
    // 确认密码
    {
        _againPdView=[[LeftTitle_TextFieldView alloc]initWithTitle:NSLocalizedString(@"SurePassword", nil) placeholder:NSLocalizedString(@"EnterSurePassword", nil)];//@"确认密码" @"请输入新密码"];

        ViewBorderRadius(_againPdView,kmargin/2,.5,ColorBDBDBD);
        [self.view addSubview:_againPdView];
        _againPdView.textField.secureTextEntry=YES;
        [_againPdView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.resetPdView.mas_bottom).offset(kmargin);
            make.left.mas_equalTo(kmargin*3);
            make.size.mas_equalTo(CGSizeMake(APPW-kmargin*6,40));
        }];
    }
    
    // 完成
    UIButton *OKBtn=[UIButton new];
    [self.view addSubview:OKBtn];
    OKBtn.backgroundColor=Main_Color;
    OKBtn.titleLabel.font=Font_Number(16);
    ViewBorderRadius(OKBtn,kmargin/2,1,ClearColor);
    [OKBtn setTitle:NSLocalizedString(@"Done", nil) forState:UIControlStateNormal];//@"完成"
    [OKBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    [OKBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.againPdView.mas_bottom).offset(kmargin*2);
        make.size.mas_equalTo(CGSizeMake(APPW-kmargin*6,40));
        make.left.mas_equalTo(kmargin*3);
    }];
    [OKBtn addTarget:self action:@selector(OKBtnEvent) forControlEvents:UIControlEventTouchUpInside];
}

// 完成
-(void)OKBtnEvent
{
    NSDictionary *dic= @{
                            @"doctor_id":[Util getUserDefaultObjectForKey:@"id"],
                            @"password":_resetPdView.textField.text,
                            @"repassword":_againPdView.textField.text
                        };

    __weak typeof(self) weakSelf=self;
    // 重置密码
    [QBRequest ResetPdWithDic:dic Success:^(id res)
    {
        
       [self.view makeToast:res[@"message"] duration:1.0 position:CSToastPositionCenter];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            // 跳转到登录界面
            LoginVC *loginVC=[LoginVC new];
            [weakSelf.navigationController pushViewController:loginVC animated:NO];
        });
        
        
    } failure:^(NSString *error) {
        
    }];
    
}

-(void)initNavBarBtnItem
{
    self.navigationItem.leftBarButtonItem=[UIBarButtonItem initWithNormalImage:@"back_gray" target:self action:@selector(backItemEvent)];
}

-(void)backItemEvent
{
    [self.navigationController popViewControllerAnimated:NO];
}


@end
